package com.itheima.d2_xml;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import javax.xml.parsers.SAXParser;
import javax.xml.transform.sax.SAXResult;
import java.util.List;

/*
     目标：掌握使用Dom4j框架解析XML文件。
 */
public class Dom4JTest1 {
    public static void main(String[] args) throws Exception {
        SAXReader sr = new SAXReader();
        Document read = sr.read("123.xml");
        Element root = read.getRootElement();
        List<Element> elements = root.elements();
        for (Element element : elements) {
            Attribute id = element.attribute("id");
            String s = id.getValue();

            Element nameel = element.element("name");
            String name = nameel.getText();

            Element ageel = element.element("age");
            String age = ageel.getText();

            Element disel = element.element("dis");
            String dis = disel.getText();
            System.out.println("id=" + id + "姓名=" + name + "age=" + age + "dis=" + dis);
        }
    }
}
